package org.deltaset.samples.petclinic.domain;

import java.util.List;
import javax.annotation.ManagedBean;
import org.deltaset.meta.annotation.DsFirstResult;
import org.deltaset.meta.annotation.DsMaxResult;

/**
 *
 * @author dmakariev
 */
@ManagedBean
public class OwnerRepositoryAddon extends AbstractRepository {

    public long countOwners() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Owner o", Long.class).getSingleResult();
    }

    public List<Owner> findAllOwners() {
        return entityManager().createQuery("SELECT o FROM Owner o", Owner.class).getResultList();
    }

    public Owner findOwner(Long id) {
        if (id == null) {
            return null;
        }
        return entityManager().find(Owner.class, id);
    }

    public List<Owner> findOwnerEntries(@DsFirstResult int firstResult, @DsMaxResult int maxResults) {
        return entityManager().createQuery("SELECT o FROM Owner o", Owner.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
}
